✨ Support new SNBT Unicode escapes from 25w09a#1953
✨ Support new SNBT Unicode escapes from 25w09a#1953Calverin wants to merge 5 commits intoSpyglassMC:mainfrom
Conversation
2 digit escapes with \x## and 8 digit escapes with \U########
For example, `\N{Snowman}`
Does not currently check if it's an actual character name.
Added a bundled Unicode lookup table for validating names, originally fetched from https://unicode.org/Public/UNIDATA/UnicodeData.txt, and added a separate extendedUnicode option for the string parser
SPGoding
left a comment
There was a problem hiding this comment.
Can we add some test cases for these new escape sequences? A few cases off the top of my mind:
- Using them when
extendedUnicodeis disabled - Using them when
extendedUnicodeis enabled - Testing various syntax errors you can have with them
And would it be possible to commit the script you used to generate the lookup table as well so we can re-run it in the future? I would prefer it if it's put under somewhere like packages/core/scripts to keep it separate from the production source code but if the script is in TypeScript you might need to update packages/core/tsconfig.json to add a project reference to it along with src and test and create a new packages/core/scripts/tsconfig.json (just putting { "extends": "../../tsconfig-type-strip" } as its content should ba fine).
misode
left a comment
There was a problem hiding this comment.
Given some of the discussion on discord, are we now sure that this JSON file 100% matches what the vanilla game accepts?
| options.escapable.unicode | ||
| && (c2 === 'u' || (options.escapable.extendedUnicode && UnicodeEscapeChar.is(c2))) | ||
| ) { | ||
| const sequenceLength = UnicodeEscapeLengths.get(c2) || 4 |
There was a problem hiding this comment.
It's more common to use ?? 4 for default values.
| cStart = src.cursor | ||
| continue | ||
| } | ||
| const name = src.peekUntil('}') |
There was a problem hiding this comment.
Minecraft actually allows whitespace between the curly braces and the name. So you might need to trim the name or add some src.skipSpace calls.
| }) | ||
| ans.value += c2 | ||
| } else if ( | ||
| /^[-a-zA-Z0-9 ]+$/.test(name) && UnicodeLookupTable.has(name.toLowerCase()) |
There was a problem hiding this comment.
Instead of doing a has() and then get()! separately, I would use a single get() and check if the result is not undefined.
Adds support in SNBT Strings for:
\x0A\U0001F525\N{Fire}(validated against this list with control characters using their secondary name and any character with parentheses in the name being omitted)Checks a box in #1771